 <template>
  <div class="app-container calendar-list-container">
    <div class="filter-container">
      <el-button class="filter-item" v-if="withdrawAccountManager_btn_add" style="margin-left: 10px;" type="success" @click="bindCard">添加</el-button>
    </div>
    <el-table  :data="list" v-loading.body="listLoading" border fit highlight-current-row style="width: 100%">
      
      <el-table-column align="center" label="平台编号" width="300">
        <template scope="scope">
          <span>{{scope.row.platformId}}</span>
        </template>
      </el-table-column>
      <el-table-column width="249px" align="center" label="商户编号">
      <template scope="scope">
        <span>{{scope.row.merchantId}}</span>
      </template>
      </el-table-column>
      <el-table-column width="300px" align="center" label="银行名称">
        <template scope="scope">
          <span>{{scope.row.bankName}}</span>
        </template>
      </el-table-column>
      <el-table-column width="300px" align="center" label="银行账户名">
        <template scope="scope">
          <span>{{scope.row.bankAccountName}}</span>
        </template>
      </el-table-column>
      <el-table-column width="300px" align="center" label="银行卡号">
        <template scope="scope">
          <span>{{scope.row.bankNo}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="250"> 
          <template scope="scope">
            <el-button size="small" v-if="withdrawAccountManager_btn_upt"  type="info" @click="handleUpdate(scope.row)">修改</el-button>
            <el-button size="small" v-if="withdrawAccountManager_btn_del" type="danger" @click="handleDelete(scope.row)">删除</el-button>
          </template>
      </el-table-column>
    </el-table>
    <div v-show="!listLoading" class="pagination-container">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="listQuery.page" :page-sizes="[10,20,30, 50]" :page-size="listQuery.limit" layout="total, sizes, prev, pager, next, jumper" :total="total"> </el-pagination>
    </div>
  </div>
</template>

<script>
import { pageAll, deleteObj, updateObj } from '@/api/crm/payForAnotherBank/index'
import { mapGetters } from 'vuex'
export default {
  name: 'functionList',
  data() {
    return {
      form: {
        id: undefined,
        bankName: '',
        bankAccountName: '',
        bankNo: '',
        platformId: '',
        merchantId: ''
      },
      rules: {
        bankName: [
          {
            required: true,
            message: '不能为空',
            trigger: 'blur'
          }
        ],
        bankAccountName: [
          {
            required: true,
            message: '不能为空',
            trigger: 'blur'
          }
        ],
        bankNo: [
          {
            required: true,
            message: '不能为空',
            trigger: 'blur'
          }
        ]
      },
      list: null,
      total: null,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20
      },
      dialogFormVisible: false,
      withdrawAccountManager_btn_del: false,
      withdrawAccountManager_btn_add: false,
      withdrawAccountManager_btn_upt: false,
      tableKey: 0,
      dialogStatus: '',
      txtMap: {
        create: '创建',
        update: '修改'
      }
    }
  },
  created() {
    this.getList()
    this.withdrawAccountManager_btn_add = this.elements['withdrawAccountManagerManager:btn_add']
    this.withdrawAccountManager_btn_del = this.elements['withdrawAccountManagerManager:btn_del']
    this.withdrawAccountManager_btn_upt = this.elements['withdrawAccountManagerManager:btn_upt']
  },
  computed: {
    ...mapGetters(['elements', 'platformId', 'merchantId'])
  },
  methods: {
    bindCard() {
      this.$router.push({ path: '/withdraw/bindCard' })
    },
    getList() {
      this.listLoading = true
      pageAll(this.listQuery).then(response => {
        this.list = response.data.rows
        this.total = response.data.total
        this.listLoading = false
      })
    },
    handleFilter() {
      this.getList()
    },
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listQuery.page = val
      this.getList()
    },
    handleUpdate(row) {
      this.form = row
      this.dialogStatus = 'update'
      this.dialogFormVisible = true
    },
    handleDelete(row) {
      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteObj(row).then(() => {
          this.$notify({
            title: '成功',
            message: '删除成功',
            type: 'success',
            duration: 2000
          })
          this.getList()
        })
      })
    },

    update(formName) {
      const set = this.$refs
      set[formName].validate(valid => {
        if (valid) {
          this.dialogFormVisible = false
          updateObj(this.form).then(() => {
            this.dialogFormVisible = false
            this.getList()
            this.$notify({
              title: '成功',
              message: '操作成功',
              type: 'success',
              duration: 2000
            })
          })
        } else {
          return false
        }
      })
    },

    resetTemp() {
      this.form = {
        id: undefined,
        bankName: '',
        bankAccountName: '',
        bankNo: ''
      }
    }
  }
}
</script>
